//File:			Collada.h
//Purpose:		Handle loading Collada .DAE model files in addition to loading basic XML files for general parsing using the Node Class
//Programmer:	Daniel Martin 3/19/2013 

#pragma once
#include <iostream>
#include <list>
#include "Model.h"
#include "TinyXML\tinyxml2.h"
using namespace tinyxml2;

class Node
{

public:

	// Technically called attributes, but "keys" makes shorter looking methods
	struct Key
	{
		std::string Name;
		std::string Value;

		Key()
		{
			Name = "NULL";
			Value = "NULL";
		}
		Key(std::string _Name,std::string _Value)
		{
			Name = _Name;
			Value = _Value;
		}
	};	

	std::string Name;
	std::list<Node> Nodes;
	std::vector<Key> Keys;
	Node* Parent, *Next, *Prev;


	Node();
	Node(std::string _Name);
	void Create(std::string _Name = "NULL");

	Node* RequestNode();
	void AddKey(std::string Name,std::string Value);
	void AddKey(Key key);


	// Recursively parse all node children for matching name
	Node* GetAnyNode(std::string Name, bool Subprocess = false);

	// Recursively parse all node children keys and self
	Key* GetAnyKey(std::string Name, bool Subprocess = false);


	// Parse only immediate child nodes for matching name
	Node* GetNode(std::string Name, int ithMatch = 1);

	// Parse only immediate node children keys and self
	Key* GetKey(std::string Name);



	bool CompareString(std::string Str1,std::string Str2);

	void MapKeys();
	void MapNodes();

	// Print a list of child nodes and attributes (keys)
	void PrintMap();
};


class Collada
{
public:	
	Collada(void);

	static void ParseKeys(XMLElement* XML, Node* N);
	static void ParseSibling(XMLElement* XML, Node* Parent);

	static Node Load(std::string Path);
	static Model LoadModel(std::string path);
};

